<script setup lang="ts">
import * as WarehouseApi from '@/api/wms/warehouse';

const warehouseId = defineModel("warehouseId");
const positionId = defineModel("positionId");

const value = computed(() => {
  let arr = [];
  const w = warehouseId.value;
  const p = positionId.value;
  if (w !== undefined && w !== null) {
    arr.push(w);
    if (p !== undefined && p !== null) {
      arr.push(p);
    }
  }
  return arr;
})

const options = ref([]); //仓库选项值
const props = {
  expandTrigger: 'hover' as const,
  value: 'id',
  label: 'name'
}

const getWarehouseTree = async () => {
  const data = await WarehouseApi.getWarehouseTree();
  options.value = data;
};
const handleChange = (value) => {
  warehouseId.value = value[0];
  positionId.value = value[1];
}

getWarehouseTree(); //获取仓库数据
</script>

<template>
  <!-- 仓库级联选择框 -->
  <el-cascader v-model="value" :props="props" :options="options" @change="handleChange" />

</template>

<style scoped lang="scss">
.content {
  overflow: hidden;
}
</style>
